<?php
namespace Admin\Controller;

class ReserveController extends PublicController {

    function _initialize() {
        parent::_initialize ();
    }

    /**
     * 获取订单
     */
    public function index()
    {
        $order_no = I('post.order_no');
        $start_time = I('post.start_time');
        $end_time = I('post.end_time');

        $store_id = session("wadmin");

        if ($store_id['store_id'] == 0) {
            $where = '';
        } else {
            $where['store_id'] = $store_id['store_id'];
        }

        if ($order_no) {
            $where['order_no'] = array('like', "%$order_no%");
        }

        if ($start_time && $end_time) {
            $where['time'] = array(array('egt', strtotime($start_time)), array('elt', strtotime($end_time)), 'AND');
        }

        //有效标志 1有效 2无效
        $where['valid_flag'] = 1;

        $count = M("reserve_order")
            ->where($where)
            ->order('time desc')
            ->count();

        $Page = new \Think\Page($count, 10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfig('theme', "<ul class='pagination no-margin pull-right'></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><a> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页</a></ul>");

        $show = $Page->show(); // 分页显示输出

        $result = M("reserve_order")
            ->field("*")
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('time desc')
            ->select();

        $this->assign("result", $result);
        $this->assign("page", $show); // 赋值分页输出

        $this->display();
    }


}